package com.chendx.store.goods.controller;

import com.chendx.model.common.dtos.ResponseResult;
import com.chendx.model.goods.dto.TemplateDto;
import com.chendx.model.goods.pojo.Template;
import com.chendx.store.api.goods.TemplateControllerApi;
import com.chendx.store.goods.service.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by chendx on 2022/5/19.
 */
@RequestMapping("/api/template")
@RestController
public class TemplateController implements TemplateControllerApi {

    @Autowired
    public TemplateService templateService;

    @Override
    @GetMapping("/all")
    public ResponseResult all() {
        List<Template> list = templateService.list();
        return ResponseResult.okResult(list);
    }

    @Override
    @PostMapping("/add")
    public ResponseResult add(@RequestBody TemplateDto dto) {
        return templateService.add(dto);
    }

    @Override
    @GetMapping("/one")
    public ResponseResult one(Integer id) {
        return ResponseResult.okResult(templateService.getById(id));
    }

    @Override
    @GetMapping("/infos")
    public ResponseResult templateInfos() {
        return templateService.templateInfos();
    }

    @Override
    @GetMapping("/oneinfo")
    public ResponseResult oneinfo(Integer id) {
        return templateService.oneinfo(id);
    }
}
